export default {
	data() {
		return {
			spanLeft: 5,
			spanRight: 19,
			data1: [],
			modal6: false,
			modal5: false,
			modal3: false,
		}
	},
	methods: {
		typeNumber() {
			this.$http.get(`http://localhost:3000/${this.models1}/list`).then(res => {
				let ll = res.data.length
				const arr = []
				for(let i = 0; i < ll; i++) {
					if(this.catetype) {
						if(res.data[i].type == this.catetype) {
							arr.push(res.data[i])
						}
					} else {
						arr.push(res.data[i])
					}
				}
				for(let i = 0; i < arr.length; i++) {
					let obj = {
						title: arr[i].text,
						expand: true,
						id: arr[i]._id,
						children: [],
					}
					this.data1.push(obj)
					if(arr[i].children) {

						this.sTree(arr[i].children, this.data1[i].children)
					}

				}

			})
		},
		okok() {
			console.log(this.updataid)
			setTimeout(() => {
				this.$http.put(`http://localhost:3000/${this.models2}/data/${this.updataid}`, this.formItem)
					.then(res => {
						this.fliter.list = []
						this.getData()

						this.data1 = []
						this.typeNumber()
					})
				this.$Modal.remove();
			}, 1000);

		},
		asyncOK() {
			this.formLeft.parentId = this.addContent[0].id
			this.$http.post(`http://localhost:3000/${this.models2}/data`, this.formLeft)
				.then(res => {
					this.fliter.list = []
					this.getData()
					this.data1 = []
					this.typeNumber()
				})
		},

		addNew() {
			if(this.addContent[0]) {
				if(this.addContent[0].children) {
					this.modal6 = true

				} else {
					this.$Message.error('对方不想说话，默默的看你选择正确的文件夹');
				}
			} else {
				this.$Message.error('对方不想说话，默默的看你选择正确的文件夹');
			}
		},
		show(index) {
			Object.assign(this.$data.formItem, this.fliter.list[index])
			this.fliter.list[index]
			this.modal5 = true
			this.updataid = this.fliter.list[index]._id
		},
		remove(index) {
			this.$Modal.confirm({
				title: '确认删除数据吗',
				content: '删除后这些数据将无法找回',
				loading: true,
				onOk: () => {
					console.log(this.fliter.list[index]._id)
					setTimeout(() => {
						this.$http.delete(`http://localhost:3000/${this.models2}/data/${this.fliter.list[index]._id}`)
							.then(res => {
								this.fliter.list = []
								this.getData()

								this.data1 = []
								this.typeNumber()
							})
						this.$Modal.remove();
					}, 1000);
				}
			});
		},
		sTree(rows, tchild) {
			let len = rows.length
			for(let i = 0; i < len; i++) {
				if(rows[i].children) {
					let obj = {
						title: rows[i].text,
						expand: true,
						id: rows[i]._id,
						children: []
					}
					tchild.push(obj)
					this.sTree(rows[i].children, tchild[i].children)
				} else {
					let catearr = []
					this.$http.get(`http://localhost:3000/${this.models2}/list`).then(resd => {
						let lls = resd.data.length
						for(let j = 0; j < lls; j++) {
							if(rows[i]._id == resd.data[j].cateId) {
								let cateobj = {
									title: resd.data[j].text,
									id: resd.data[j]._id,
									number: resd.data[j].number,
								}
								catearr.push(cateobj)
							}
						}
						let obj = {
							title: rows[i].text,
							expand: true,
							id: rows[i]._id,
							children: catearr
						}
						tchild.push(obj)
					})

				}
			}
		}
	},
	created() {
		this.getData()
		this.typeNumber()
	}
}